import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:business_plugin/business/config_business/config_business.dart';
import 'package:business_plugin/business/report_utils/report_utils.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as developer;

class BusinessTools {
  //打印日志
  static void log(String msg) {
    if (ConfigBusiness.config.debugEnabled == true) {
      developer.log(msg);
    } else {
      debugPrint(msg);
    }
  }

  static TrackingStatus? status;
  static Future<TrackingStatus> getAttPermission({Function? callback}) async {
    //先判断是否有ATT权限
    status ??= await AppTrackingTransparency.trackingAuthorizationStatus;
    if (status == TrackingStatus.notDetermined) {
      // 请求系统权限
      status = await AppTrackingTransparency.requestTrackingAuthorization();
      //上报
      ReportUtils.logEvent("att_show", properties: null);
      if (status == TrackingStatus.authorized) {
        //上报
        ReportUtils.logEvent("att_success", properties: null);
      } else if (status == TrackingStatus.denied || status == TrackingStatus.restricted) {
        //上报
        ReportUtils.logEvent("att_reject", properties: null);
      }
      callback?.call();
    }
    return status!;
  }
}
